package javacode.chapter07.homework;

public class Homework06 {
    public static void main(String[] args) {
        Cale cale = new Cale(10.5, 20.3);
        System.out.println(cale.add());
        System.out.println(cale.subtract());
        System.out.println(cale.multiply());
        System.out.println(cale.devide());
    }
}

/**
 * 编程创建一个Cale计算类，在其中定义2个变量表示两个操作数，
 * 定义四个方法实现求和、差、乘、商（要求除数为0的话，要提示）并创建两个对象，分别测试
 */

class Cale {
    double count1;
    double count2;

    Cale(double count1, double count2) {
        this.count1 = count1;
        this.count2 = count2;
    }

    //求和
    double add() {
        return count1 + count2;
    }

    //差
    double subtract() {
        return count1 - count2;
    }

    //乘
    double multiply() {
        return count1 * count2;
    }

    //商
    Double devide() {
        if (count2 == 0) {
            System.out.println("除数不能为0");
            return null;
        } else {
            return count1 / count2;
        }
    }
}